﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ChinaGS.Lian.ModuleRemoting;
using System.Data.SqlClient;


public partial class pay_train_fill_mobile_bill : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SysCommon.checkUserLogin();

        if (!IsPostBack)
        {            
            String AccpetType = Request["HidAccpetType"];
            String Charge = Request["HidCharge"];
            String ReceiPay = Request["HidReceiPay"];
            String cusNo = Request["HidcusNo"];

            if (Request["HidAccpetType"] != null)
            {
                if (AccpetType.Equals("s10"))//全球通
                {
                    //显示查询结果     
                    this.LabChargeName.Text = "本期账单";
                    this.LabCharge.Text = ReceiPay;
                }
                else
                { //预付费s30 s30

                    //显示查询结果            
                    this.LabChargeName.Text = "账户余额";
                    this.LabCharge.Text = Charge;
                }

                HidAccpetType.Value = AccpetType;
                HidCharge.Value = Charge;
                HidReceiPay.Value = ReceiPay;
                HidcusNo.Value = cusNo;

                PanPay.Visible = true;

            }
            else {
                PanPay.Visible = false;
                this.LabMessage.Text = "操作失败，请重试！";
            
            }                    
        }
    }


    protected void NextStep_Click(object sender, EventArgs e)
    {        
        try
        {
            //充值前操作            
            int user_paid_id = DataBaseOperate_SQLServer.execPPaidAtonce(Session["user_id"].ToString(), "1".ToString(), HidcusNo.Value, 
                TexPayMoney.Text, TexPayMoney.Text, "0".ToString(), "0".ToString(), "0".ToString(), System.DateTime.Now.ToString(), "none".ToString());
            
            if (user_paid_id < 0)
            {
                LabMessage.Text = "操作失败！原因是：" + RemotingClass.alertExecErroeResult(user_paid_id).ToString() + "，请重试";
                PanPay.Visible = false;
            }
            else {
                MobilePackage mp = RemotingClass.mobilePayMoney(HidcusNo.Value, HidAccpetType.Value, System.Convert.ToDouble(TexPayMoney.Text));
                //测试使用
                /*MobilePackage mp = new MobilePackage();
                mp.Status = true;
                mp.StatusNo = "00";
                mp.AccpetType = "s10";
                mp.Charge = 120.0;
                mp.ReceiPay = 100.0;
                mp.AccpetTypeCN = "全球通";
                mp.SerialNo = "1234567890";//	交易流水号	缴费时返回
                mp.Message = "success"; //返回消息	根据状态码不同为不同消息
                mp.StatusNo = "00";//状态码	见状态码定义       
                mp.ItemNo = "123456";//合同号
                mp.CusNo = HidcusNo.Value;//	客户号码
                mp.CusName = "denveryee";//	客户名称            
                mp.RealPay = System.Convert.ToDouble(TexPayMoney.Text);	//实收金额
                mp.PayDate = DateTime.Now.ToString("yyyy年MM月dd日"); 	//付款日期*/


                if (mp.Status)
                {
                    //充值成功操作                
                    DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), mp.SerialNo,
                        mp.CusNo, mp.Message, "1".ToString(), SysCommon.getClientIP(), "0".ToString());

                    Response.Redirect("paysuccess_mobile.aspx?HidRealPay=" + mp.RealPay
                                        + "&HidCharge=" + mp.Charge.ToString()
                                        + "&HidReceiPay=" + mp.ReceiPay.ToString()
                                        + "&HidPayDate=" + mp.PayDate
                                        + "&HidcusNo=" + mp.CusNo);
                }
                else
                {
                    //充值失败操作
                    DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), mp.SerialNo,
                         mp.CusNo, mp.Message, "2".ToString(), SysCommon.getClientIP(), "0".ToString());

                    LabMessage.Text = "操作失败！原因是：" + mp.Message + "，请稍后重试";
                    PanPay.Visible = false;
                }   
            
            }           

             
        }
        catch (Exception ex)
        {
            Log.Record(ex);            
        }
                
    }

    
}
